/*
 * 菜单接口
 * @Description: jishupu-admin-template
 * @Author: 技术铺<jishupu@qq.com>
 * @Date: 2021-11-15
 */
import request from '@/utils/request'

/**
 * 列表
 * @param {Object} params
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function index(params, extendConfig) {
  return request.get('/v1/menu', { params, ...extendConfig })
}

/**
 * 添加
 * @param {Object} params
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function store(params, extendConfig) {
  return request.post('/v1/menu', params, extendConfig)
}

/**
 * 查看
 * @param {Number} id 标识
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function show(id, extendConfig) {
  return request.get('/v1/menu/' + id, extendConfig)
}

/**
 * 修改
 * @param {Number} id
 * @param {Object} params
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function update(id, params, extendConfig) {
  return request.put(`/v1/menu/${id}`, params, extendConfig)
}

/**
 * 删除
 * @param {Number} id 标识
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function destory(id, extendConfig) {
  return request.delete(`/v1/menu/${id}`, extendConfig)
}

/**
 * 更新状态
 * @param {Number} id 标识
 * @param {Object} params 参数如：{ status: 0 }
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function updateStatus(id, params, extendConfig) {
  return request.patch(`/v1/menu/${id}/status`, params, extendConfig)
}

/**
 * 更新排序
 * @param {Object} params 参数如：{sort: [{id: 7, sort: 2}, {id: 8, sort: 1}]}
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function updateSort(params, extendConfig) {
  return request.put(`/v1/menu/sort`, params, extendConfig)
}

/**
 * 获取上级菜单树
 * @param {Number} id 标识
 * @returns  new Promise
 */
export function getParentTreeConfig(id) {
  return request.get(`/v1/menu/${id}/parent-tree-config`)
}

/**
 * 获取角色的菜单列表
 * @returns  new Promise
 */
export function getRoleMenuConfig() {
  return request.get(`/v1/menu/role-menu-config`)
}

/**
 * 获取登录用户菜单配置
 * @returns  new Promise
 */
export function getUserMenuConfig() {
  return request.get('/v1/menu/user-menu-config')
}

/**
 * 获取登录用户菜单：测试数据
 * @returns  new Promise
 */
export function getUserMenuDemo() {
  return [{
    path: '/info',
    name: 'Info',
    redirect: 'noRedirect',
    meta: {
      title: '信息管理',
      icon: 'awesome-icon far fa-newspaper',
      roles: ['admin']
    },
    component: '/layout',
    alwaysShow: true,
    children: [{
      name: 'InfoManagement',
      path: '/info-management',
      alwaysShow: true,
      component: '/empty',
      redirect: 'noRedirect',
      meta: {
        title: '内容管理',
        icon: 'awesome-icon far fa-edit',
        roles: ['admin'],
        breadcrumb: false,
        isTree: true
      },
      children: [{
        name: 'InfoCategory2InfoNews',
        path: '/info-category/2/info-news',
        component: '/empty',
        alwaysShow: false,
        redirect: '/info-category/2/info-news/index',
        meta: {
          title: '新闻栏目2',
          roles: ['admin']
        },
        children: [{
          name: 'InfoCategory2InfoNewsIndex',
          path: '/info-category/2/info-news/index',
          component: '/info-news/index',
          hidden: true,
          meta: {
            title: '列表',
            roles: ['admin'],
            activeMenu: '/info-category/2/info-news',
            infoCategory: {
              id: 2
            }
          }
        }, {
          name: 'InfoCategory2InfoNewsCreate',
          path: '/info-category/2/info-news/create',
          component: '/info-news/edit',
          hidden: true,
          meta: {
            title: '添加',
            roles: ['admin'],
            activeMenu: '/info-category/2/info-news',
            infoCategory: {
              id: 2
            }
          }
        }, {
          name: 'InfoCategory2InfoNewsEdit',
          path: '/info-category/2/info-news/:id(\\d+)/edit',
          component: '/info-news/edit',
          hidden: true,
          meta: {
            title: '修改',
            roles: ['admin'],
            activeMenu: '/info-category/2/info-news',
            infoCategory: {
              id: 2
            }
          }
        }]
      },
      {
        name: 'InfoCategory3InfoNews',
        path: '/info-category/3/info-news',
        component: '/empty',
        alwaysShow: false,
        redirect: '/info-category/3/info-news/index',
        meta: {
          title: '新闻栏目3',
          roles: ['admin']
        },
        children: [{
          name: 'InfoCategory3InfoNewsIndex',
          path: '/info-category/3/info-news/index',
          component: '/info-news/index',
          hidden: true,
          meta: {
            title: '列表',
            roles: ['admin'],
            activeMenu: '/info-category/3/info-news',
            infoCategory: {
              id: 3
            }
          }
        }, {
          name: 'InfoCategory3InfoNewsCreate',
          path: '/info-category/3/info-news/create',
          component: '/info-news/edit',
          hidden: true,
          meta: {
            title: '添加',
            roles: ['admin'],
            activeMenu: '/info-category/3/info-news',
            infoCategory: {
              id: 3
            }
          }
        }, {
          name: 'InfoCategory3InfoNewsEdit',
          path: '/info-category/3/info-news/:id(\\d+)/edit',
          component: '/info-news/edit',
          hidden: true,
          meta: {
            title: '修改',
            roles: ['admin'],
            activeMenu: '/info-category/3/info-news',
            infoCategory: {
              id: 3
            }
          }
        }]
      },
      {
        name: 'InfoCategory9InfoPicture',
        path: '/info-category/9/info-picture',
        component: '/empty',
        alwaysShow: false,
        redirect: '/info-category/9/info-picture/index',
        meta: {
          title: '图集1',
          roles: ['admin']
        },
        children: [{
          name: 'InfoCategory9InfoPictureIndex',
          path: '/info-category/9/info-picture/index',
          component: '/info-picture/index',
          hidden: true,
          meta: {
            title: '列表',
            roles: ['admin'],
            activeMenu: '/info-category/9/info-picture',
            infoCategory: {
              id: 9
            }
          }
        }, {
          name: 'InfoCategory9InfoPictureCreate',
          path: '/info-category/9/info-picture/create',
          component: '/info-picture/edit',
          hidden: true,
          meta: {
            title: '添加',
            roles: ['admin'],
            activeMenu: '/info-category/9/info-picture',
            infoCategory: {
              id: 9
            }
          }
        }, {
          name: 'InfoCategory9InfoPictureEdit',
          path: '/info-category/9/info-picture/:id(\\d+)/edit',
          component: '/info-picture/edit',
          hidden: true,
          meta: {
            title: '修改',
            roles: ['admin'],
            activeMenu: '/info-category/9/info-picture',
            infoCategory: {
              id: 9
            }
          }
        }]
      },
      {
        name: 'InfoCategory5InfoPageEdit',
        path: '/info-category/5/info-page/edit',
        component: '/info-page/edit',
        meta: {
          title: '公司介绍1',
          roles: ['admin'],
          infoCategory: {
            id: 5
          }
        }
      },
      {
        name: 'InfoCategory6InfoPageEdit',
        path: '/info-category/6/info-page/edit',
        component: '/info-page/edit',
        meta: {
          title: '联系方式',
          roles: ['admin'],
          infoCategory: {
            id: 6
          }
        }
      }
      ]
    }, {
      path: '/navigation',
      name: 'Navigation',
      component: '/empty',
      meta: {
        title: '导航管理',
        icon: 'el-icon-s-promotion',
        roles: ['admin']
      },
      alwaysShow: false,
      redirect: '/navigation/index',
      children: [{
        name: 'NavigationIndex',
        path: '/navigation/index',
        component: '/navigation/index',
        hidden: true,
        meta: {
          title: '列表',
          roles: ['admin'],
          activeMenu: '/navigation'
        }
      }, {
        name: 'NavigationCreate',
        path: '/navigation/create',
        component: '/navigation/edit',
        hidden: true,
        meta: {
          title: '添加',
          roles: ['admin'],
          activeMenu: '/navigation'
        }
      }, {
        name: 'NavigationEdit',
        path: '/navigation/:id(\\d+)/edit',
        component: '/navigation/edit',
        hidden: true,
        meta: {
          title: '修改',
          roles: ['admin'],
          activeMenu: '/navigation'
        }
      }]
    },
    {
      name: 'InfoCategory',
      path: '/info-category',
      component: '/empty',
      alwaysShow: false,
      redirect: '/info-category/index',
      meta: {
        title: '栏目分类',
        icon: 'tree',
        roles: ['admin']
      },
      children: [{
        name: 'InfoCategoryIndex',
        path: '/info-category/index',
        component: '/info-category/index',
        hidden: true,
        meta: {
          title: '列表',
          roles: ['admin'],
          activeMenu: '/info-category'
        }
      }, {
        name: 'InfoCategoryCreate',
        path: '/info-category/create',
        component: '/info-category/edit',
        hidden: true,
        meta: {
          title: '添加',
          roles: ['admin'],
          activeMenu: '/info-category'
        }
      },
      {
        name: 'InfoCategoryEdit',
        path: '/info-category/:id(\\d+)/edit',
        component: '/info-category/edit',
        hidden: true,
        meta: {
          title: '修改',
          roles: ['admin'],
          activeMenu: '/info-category'
        }
      }
      ]
    },
    {
      name: 'InfoModel',
      path: '/info-model',
      component: '/empty',
      meta: {
        title: '信息模型',
        icon: 'awesome-icon fas fa-database',
        roles: ['admin'],
        breadcrumb: false
      },
      alwaysShow: false,
      redirect: '/info-model/index',
      children: [{
        name: 'InfoModelindex',
        path: '/info-model/index',
        component: '/info-model/index',
        hidden: true,
        meta: {
          title: '列表',
          icon: 'awesome-icon fas fa-database',
          roles: ['admin'],
          activeMenu: '/info-model'
        }
      }]
    }
    ]
  },
  {
    path: '/marketing',
    name: 'Marketing',
    component: '/layout',
    redirect: 'noRedirect',
    alwaysShow: true,
    meta: {
      title: '营销管理',
      icon: 'component',
      roles: ['admin']
    },
    children: [{
      name: 'AdsSpace',
      path: '/ads-space',
      alwaysShow: false,
      component: '/empty',
      redirect: '/ads-space/index',
      meta: {
        title: '广告位',
        icon: 'awesome-icon fab fa-buysellads',
        roles: ['admin']
      },
      children: [{
        name: 'AdsSpaceIndex',
        path: '/ads-space/index',
        component: '/ads-space/index',
        hidden: true,
        meta: {
          title: '列表',
          roles: ['admin'],
          activeMenu: '/ads-space'
        }
      },
      {
        name: 'AdsSpaceCreate',
        path: '/ads-space/create',
        component: '/ads-space/edit',
        hidden: true,
        meta: {
          title: '添加',
          roles: ['admin'],
          activeMenu: '/ads-space'
        }
      },
      {
        name: 'AdsSpaceEdit',
        path: '/ads-space/:id(\\d+)/edit',
        component: '/ads-space/edit',
        hidden: true,
        meta: {
          title: '修改',
          roles: ['admin'],
          activeMenu: '/ads-space'
        }
      }
      ]
    },
    {
      name: 'Ads',
      path: '/ads',
      hidden: true,
      component: '/empty',
      redirect: 'noRedirect',
      meta: {
        title: '广告',
        roles: ['admin']
      },
      children: [{
        name: 'AdsIndex',
        path: '/ads-space/:space_id(\\d+)/ads/index',
        component: '/ads/index',
        hidden: true,
        meta: {
          title: '列表',
          roles: ['admin'],
          activeMenu: '/ads-space'
        }
      }, {
        name: 'AdsCreate',
        path: '/ads-space/:space_id(\\d+)/ads/create',
        component: '/ads/edit',
        hidden: true,
        meta: {
          title: '添加',
          roles: ['admin'],
          activeMenu: '/ads-space'
        }
      }, {
        name: 'AdsEdit',
        path: '/ads-space/:space_id(\\d+)/ads/:id(\\d+)/edit',
        component: '/ads/edit',
        hidden: true,
        meta: {
          title: '修改',
          roles: ['admin'],
          activeMenu: '/ads-space'
        }
      }]
    }, {
      name: 'Links',
      path: '/links',
      component: '/empty',
      meta: {
        title: '友情链接',
        icon: 'awesome-icon fas fa-link',
        roles: ['admin']
      },
      alwaysShow: false,
      redirect: '/links/index',
      children: [{
        name: 'LinksIndex',
        path: '/links/index',
        component: '/links/index',
        hidden: true,
        meta: {
          title: '列表',
          roles: ['admin'],
          activeMenu: '/links'
        }
      }, {
        name: 'LinksCreate',
        path: '/links/create',
        component: '/links/edit',
        meta: {
          title: '添加',
          roles: ['admin'],
          activeMenu: '/links'
        },
        hidden: true
      }, {
        name: 'LinksEdit',
        path: '/links/:id(\\d+)/edit',
        component: '/links/edit',
        hidden: true,
        meta: {
          title: '修改',
          roles: ['admin'],
          activeMenu: '/links'
        }
      }]
    }, {
      name: 'Guestbook',
      path: '/guestbook',
      component: '/empty',
      meta: {
        title: '留言咨询',
        icon: 'message',
        roles: ['admin']
      },
      alwaysShow: false,
      redirect: '/guestbook/index',
      children: [{
        name: 'GuestbookIndex',
        path: '/guestbook/index',
        component: '/guestbook/index',
        hidden: true,
        meta: {
          title: '列表',
          roles: ['admin'],
          activeMenu: '/guestbook'
        }
      }]
    }
    ]
  },
  {
    path: '/system',
    name: 'System',
    component: '/layout',
    redirect: 'noRedirect',
    alwaysShow: true,
    meta: {
      title: '系统管理',
      icon: 'awesome-icon fas fa-tools',
      roles: ['admin']
    },
    children: [{
      name: 'Config',
      path: '/config',
      component: '/config/edit',
      alwaysShow: false,
      meta: {
        title: '系统配置',
        icon: 'el-icon-set-up',
        roles: ['admin']
      }
    }, {
      path: '/user',
      name: 'User',
      component: '/empty',
      alwaysShow: false,
      redirect: '/user/index',
      meta: {
        title: '管理员',
        icon: 'awesome-icon fas fa-users-cog',
        roles: ['admin']
      },
      children: [{
        name: 'UserIndex',
        path: '/user/index',
        component: '/user/index',
        hidden: true,
        meta: {
          title: '列表',
          roles: ['admin'],
          activeMenu: '/user'
        }
      }, {
        name: 'UserCreate',
        path: '/user/create',
        component: '/user/edit',
        meta: {
          title: '添加',
          roles: ['admin'],
          activeMenu: '/user'
        },
        hidden: true
      }, {
        name: 'UserEdit',
        path: '/user/:id(\\d+)/edit',
        component: '/user/edit',
        hidden: true,
        meta: {
          title: '修改',
          roles: ['admin'],
          activeMenu: '/user'
        }
      }]
    }, {
      path: '/role',
      name: 'Role',
      component: '/empty',
      alwaysShow: false,
      redirect: '/role/index',
      meta: {
        title: '角色管理',
        icon: 'awesome-icon far fa-address-card',
        roles: ['admin']
      },
      children: [{
        name: 'RoleIndex',
        path: '/role/index',
        component: '/role/index',
        hidden: true,
        meta: {
          title: '列表',
          roles: ['admin'],
          activeMenu: '/role'
        }
      }, {
        name: 'RoleCreate',
        path: '/role/create',
        component: '/role/edit',
        hidden: true,
        meta: {
          title: '添加',
          roles: ['admin'],
          activeMenu: '/role'
        }
      }, {
        name: 'RoleEdit',
        path: '/role/:id(\\d+)/edit',
        component: '/role/edit',
        hidden: true,
        meta: {
          title: '修改',
          roles: ['admin'],
          activeMenu: '/role'
        }
      }]
    }, {
      name: 'Menu',
      path: '/menu',
      component: '/empty',
      alwaysShow: false,
      redirect: '/menu/index',
      meta: {
        title: '菜单管理',
        icon: 'tree-table',
        roles: ['admin']
      },
      children: [{
        name: 'MenuIndex',
        path: '/menu/index',
        component: '/menu/index',
        hidden: true,
        meta: {
          title: '列表',
          roles: ['admin'],
          activeMenu: '/menu'
        }
      }, {
        name: 'MenuCreate',
        path: '/menu/create',
        component: '/menu/edit',
        hidden: true,
        meta: {
          title: '添加',
          roles: ['admin'],
          activeMenu: '/menu'
        }
      }, {
        name: 'MenuEdit',
        path: '/menu/:id(\\d+)/edit',
        component: '/menu/edit',
        hidden: true,
        meta: {
          title: '修改',
          roles: ['admin'],
          activeMenu: '/menu'
        }
      }]
    }, {
      name: 'Permission',
      path: '/permission',
      component: '/empty',
      alwaysShow: false,
      redirect: '/permission/index',
      meta: {
        title: '权限管理',
        icon: 'tree-table',
        roles: ['admin']
      },
      children: [{
        name: 'PermissionIndex',
        path: '/permission/index',
        component: '/permission/index',
        hidden: true,
        meta: {
          title: '列表',
          roles: ['admin'],
          activeMenu: '/permission'
        }
      }]
    }, {
      name: 'Dictionary',
      path: '/dictionary',
      component: '/empty',
      meta: {
        title: '数据字典',
        icon: 'el-icon-notebook-2',
        roles: ['admin']
      },
      alwaysShow: false,
      redirect: '/dictionary/index',
      children: [{
        name: 'DictionaryIndex',
        path: '/dictionary/index',
        component: '/dictionary/index',
        hidden: true,
        meta: {
          title: '列表',
          roles: ['admin'],
          activeMenu: '/dictionary'
        }
      },
      {
        name: 'DictionaryCreate',
        path: '/dictionary/create',
        component: '/dictionary/edit',
        hidden: true,
        meta: {
          title: '添加',
          roles: ['admin'],
          activeMenu: '/dictionary'
        }
      },
      {
        name: 'DictionaryEdit',
        path: '/dictionary/:id(\\d+)/edit',
        component: '/dictionary/edit',
        hidden: true,
        meta: {
          title: '修改',
          roles: ['admin'],
          activeMenu: '/dictionary'
        }
      }
      ]
    },
    {
      name: 'DictionaryItems',
      path: '/dictionary-items',
      component: '/empty',
      hidden: true,
      redirect: 'noRedirect',
      meta: {
        title: '字典选项',
        roles: ['admin'],
        activeMenu: '/dictionary'
      },
      children: [{
        name: 'DictionaryItemsIndex',
        path: '/dictionary/:did(\\d+)/dictionary-items/index',
        component: '/dictionary-items/index',
        hidden: true,
        meta: {
          title: '列表',
          roles: ['admin'],
          activeMenu: '/dictionary'
        }
      },
      {
        name: 'DictionaryItemsCreate',
        path: '/dictionary/:did(\\d+)/dictionary-items/create',
        component: '/dictionary-items/edit',
        hidden: true,
        meta: {
          title: '添加',
          roles: ['admin'],
          activeMenu: '/dictionary'
        }
      },
      {
        name: 'DictionaryItemsEdit',
        path: '/dictionary/:did(\\d+)/dictionary-items/:id(\\d+)/edit',
        component: '/dictionary-items/edit',
        hidden: true,
        meta: {
          title: '修改',
          roles: ['admin'],
          activeMenu: '/dictionary'
        }
      }
      ]
    }, {
      name: 'AdminLogManager',
      path: '/admin-log-manager',
      component: '/empty',
      alwaysShow: true,
      meta: {
        title: '日志管理',
        icon: 'awesome-icon fas fa-history',
        roles: ['admin']
      },
      children: [{
        name: 'AdminLog',
        path: '/admin-log',
        component: '/admin-log/index',
        meta: {
          title: '操作日志',
          roles: ['admin']
        }
      }, {
        name: 'AdminLogLogin',
        path: '/admin-log/login',
        component: '/admin-log/login',
        meta: {
          title: '登录日志',
          roles: ['admin']
        }
      }]
    }
    ]
  },
  {
    path: 'https://jishupu.com',
    component: '/layout',
    children: [{
      path: 'https://jishupu.com',
      meta: {
        title: '外部链接',
        icon: 'link',
        roles: ['admin']
      }
    }]
  }
  ]
}

